<template>
  <div v-loading="delLoading">
    <Search :search="search" :reset="reset">
      <template v-slot:body>
        <el-form-item label="报表名称" prop="report_name">
          <el-input v-model="query.report_name" name="report_name" clearable />
        </el-form-item>
        <el-form-item label="视图表名" prop="table_name">
          <el-input v-model="query.table_name" name="table_name" clearable />
        </el-form-item>
      </template>
    </Search>
    <div class="table-default">
      <Operate :show="open" />
      <el-table :data="tableData" class="mt-3" v-loading="loading" border>
        <el-table-column prop="report_name" label="报表名称" />
        <el-table-column prop="table_name" label="视图表名" />
        <el-table-column prop="route_path" label="路由" />
        <el-table-column prop="component" label="所属组件" width="350">/CustomReport/views/customReport/view.vue</el-table-column>
        <el-table-column prop="created_at" label="创建时间" />
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <Update @click="open(scope.row.id)" />
            <Destroy @click="destroy(api, scope.row.id)" />
          </template>
        </el-table-column>
      </el-table>
      <Paginate />
    </div>

    <Dialog v-model="visible" :title="title" destroy-on-close width="90%">
      <Create @close="close(reset)" :primary="id" :api="api" />
    </Dialog>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import { useRouter, useRoute } from 'vue-router'
const route = useRoute()
const router = useRouter()

console.log('获取路由route',route.path);
// console.log('获取路由router',router);
const api = 'customReport/manage'

const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted,delLoading } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

onMounted(() => {
  search()
  deleted(reset)
})
</script>
